<?php
function free($userID)
{
	$query = "SELECT * FROM requests WHERE autorID=$userID OR guestID=$userID";
	$result = mysql_query($query);
	if (!$result)
		return -1;
	elseif (mysql_num_rows($result))
		return 1;
	else
	{
		$query = "SELECT * FROM battles WHERE (autorID=$userID OR guestID=$userID) AND finish=0";
		$result = mysql_query($query);
		if (!$result)
			return -1;
		elseif (mysql_num_rows($result))
			return 2;
		else
			return 0;
	}
}
?>